﻿Public Class MASPRODUCT
    Private IDMASPRODUCTTYPE As Integer
    Private TYPENAME As String
    Private STATUS = Nothing
    Private SelectProductType = Nothing
    Dim connect As CONDB = CONDB.NewConnection
    Property SelectProductType_() As String
        Get
            SelectProductType = "SELECT `idmasproducttype` as 'รหัส',`typename` as 'ประเภทสินค้า',`status` as 'สถานะการเปิดใช้งาน' FROM cpm.masproducttype ;"
            Return SelectProductType
        End Get
        Set(value As String)

        End Set
    End Property
    Property STATUS_() As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property
    Property TYPENAME_() As String
        Get
            Return TYPENAME
        End Get
        Set(value As String)
            TYPENAME = value
        End Set
    End Property
    Property IDMASPRODUCTTYPE_() As Integer
        Get
            Return IDMASPRODUCTTYPE
        End Get
        Set(value As Integer)
            IDMASPRODUCTTYPE = value
        End Set
    End Property
    Public Sub insertMasProducttype()
        connect = CONDB.NewConnection()
        connect.BeginTrans()
        Try
            Dim sql As String
            sql = "INSERT INTO cpm.masproducttype"
            sql += "(`typename`)"
            sql += "VALUES ("
            sql += "'" & TYPENAME & "')"
            connect.ExecuteNonQuery(sql)
            connect.CommitTrans()
            MsgBox("ท่านได้ทำการบันทึกข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
        Catch ex As Exception
            connect.RollbackTrans()
            MsgBox(ex.ToString)
        Finally
            connect.Dispose()
        End Try
    End Sub
    Public Sub editMasProducttype()
            connect = CONDB.NewConnection()
            connect.BeginTrans()
            Try
                Dim sql As String
            sql = "UPDATE cpm.masproducttype SET"
            sql += "`typename` = '" & TYPENAME & "'"
            sql += "WHERE `idmasproducttype` = '" & IDMASPRODUCTTYPE & "';"
            connect.ExecuteNonQuery(sql)
            connect.CommitTrans()
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            Finally
                connect.Dispose()
            End Try
    End Sub
End Class
